package com.study.a01mystream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Predicate;

public class StreamDemo6 {
    public static void main(String[] args) {

        ArrayList<String> list=new ArrayList<>();
        Collections.addAll(list,"1","2","3","4","5","6","7","8","9","10");
/*

        list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                //如果返回值为true，表示数据留下
                //如果返回值为false，表示数据被舍弃

                return s.startsWith("1");
            }
        }).forEach(s-> System.out.println(s));
*/

        //化简
        list.stream()
                .filter(s->s.startsWith("1"))
                .filter(s->s.length()==1)
                .forEach(s-> System.out.println(s));


        System.out.println("----------------");

        //limit   取前几个
        list.stream()
                .limit(3)
                .forEach(s-> System.out.println(s));

        System.out.println("----------------");

        //skip   跳过前几个
        list.stream()
                .skip(3)
                .forEach(s-> System.out.println(s));


        System.out.println("----------------");

        list.stream()
                .skip(3)
                .limit(3)
                .forEach(s-> System.out.println(s));


    }
}
